package org.elasticsearch.plugin.index.query.cnn;

import java.io.IOException;

import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.BaseQueryBuilder;
import org.elasticsearch.index.query.BoostableQueryBuilder;

public class CNNQueryBuilder extends BaseQueryBuilder implements BoostableQueryBuilder<CNNQueryBuilder> {

	private final String fieldName;

    private String feature;

    private String data;

    private String hash;

    private float boost = -1;

    private int limit = -1;

    private String lookupIndex;

    private String lookupType;

    private String lookupId;

    private String lookupRouting;

    private String lookupPath;

    public CNNQueryBuilder(String fieldName) {
        this.fieldName = fieldName;
    }

    public CNNQueryBuilder feature(String feature) {
        this.feature = feature;
        return this;
    }

    public CNNQueryBuilder data(String data) {
        this.data = data;
        return this;
    }

    public CNNQueryBuilder hash(String hash) {
        this.hash = hash;
        return this;
    }

    public CNNQueryBuilder limit(int limit) {
        this.limit = limit;
        return this;
    }

    public CNNQueryBuilder lookupIndex(String lookupIndex) {
        this.lookupIndex = lookupIndex;
        return this;
    }

    public CNNQueryBuilder lookupType(String lookupType) {
        this.lookupType = lookupType;
        return this;
    }

    public CNNQueryBuilder lookupId(String lookupId) {
        this.lookupId = lookupId;
        return this;
    }

    public CNNQueryBuilder lookupPath(String lookupPath) {
        this.lookupPath = lookupPath;
        return this;
    }

    public CNNQueryBuilder lookupRouting(String lookupRouting) {
        this.lookupRouting = lookupRouting;
        return this;
    }

    @Override
    public CNNQueryBuilder boost(float boost) {
        this.boost = boost;
        return this;
    }

    @Override
    protected void doXContent(XContentBuilder builder, Params params) throws IOException {
        builder.startObject(LSHQueryParser.NAME);

        builder.startObject(fieldName);
        builder.field("feature", feature);

        if (data != null) {
            builder.field("CNN", data);
        }


        if (lookupIndex != null) {
            builder.field("index", lookupIndex);
        }
        builder.field("type", lookupType);

        if (hash != null) {
            builder.field("hash", hash);
        }

        if (limit != -1) {
            builder.field("limit", limit);
        }

        builder.endObject();

        builder.endObject();
    }

}
